package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.FirstBuyRecord;
import com.sc.nft.mapper.FirstBuyRecordMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 优先购次数记录表(sc_first_buy_record)数据DAO
 *
 * @author kancy
 * @since 2022-08-05 00:11:39
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class FirstBuyRecordDao extends ServiceImpl<FirstBuyRecordMapper, FirstBuyRecord> {

    public List<FirstBuyRecord> getByProductIdAndCollectionUuid(Long productId,String collectionUuid){
        LambdaQueryWrapper<FirstBuyRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(FirstBuyRecord::getProductId,productId);
        wrapper.eq(FirstBuyRecord::getCollectionUuid,collectionUuid);
        return list(wrapper);
    }

    public FirstBuyRecord getByCollectionUuid(String collectionUuid){
        LambdaQueryWrapper<FirstBuyRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(FirstBuyRecord::getCollectionUuid,collectionUuid);
        wrapper.last("order by id desc limit 1");
        return getOne(wrapper);
    }

    public List<FirstBuyRecord> getByProductIdAndUserId(Long productId,Long userId){
        LambdaQueryWrapper<FirstBuyRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(FirstBuyRecord::getProductId,productId);
        wrapper.eq(FirstBuyRecord::getUserId,userId);
        wrapper.eq(FirstBuyRecord::getType,2);
        return list(wrapper);
    }
}